<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBasicStepTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        // 平台管理员登录信息表
        Schema::create('admin_users', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->unique()->comment('登录账号');
            $table->string('password')->comment('登录密码');
            $table->boolean('is_staff')->default(false)->comment('身份标识 true：教职工；false：学生；');
            $table->rememberToken()->comment('登录token');
            $table->softDeletes();
            $table->timestamps();
        });


        // 学期基础数据表
        Schema::create('basic_terms', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->unique()->comment('学期编码');
            $table->string('name')->comment('学期名称');
            $table->softDeletes();
            $table->timestamps();
        });

        // 部门基础数据表
        Schema::create('basic_departments', function (Blueprint $table) {
            // 表结构
            $table->increments('id')->comment('自增ID');
            $table->string('code')->unique()->comment('部门编码');
            $table->string('name')->comment('部门名称');
            $table->string('telephone')->nullable()->comment('联系电话');
            $table->string('parent_code')->default('0')->comment('上级部门编号');
            $table->integer('show_level')->default(0)->comment('显示级别 正序');
            $table->string('principal')->nullable()->comment('部门负责人');
            $table->softDeletes();
            $table->timestamps();
        });

        // 教职工基础数据表
        Schema::create('basic_faculties', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->unique()->comment('教职工编号');
            $table->string('name')->comment('姓名');
            $table->string('avatar')->nullable()->comment('头像');
            $table->string('department_code')->comment('所属部门编码');
            $table->string('mobile',16)->unique()->comment('手机号码');
            $table->string('telephone')->nullable()->comment('办公电话');
            $table->string('email')->nullable()->comment('电子邮箱');
            $table->string('title')->nullable()->comment('职务');
            $table->string('specialty')->nullable()->comment('专业特长');
            $table->softDeletes();
            $table->timestamps();

            // 外键关联
            $table->foreign('department_code')->references('code')->on('basic_departments')
                ->onDelete('restrict')->onUpdate('cascade');
        });


        // 校区数据表
        Schema::create('basic_colleges', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->unique()->comment('校区代码');
            $table->string('name')->comment('校区名称');
            $table->string('address')->comment('校区地址');
            $table->decimal('longitude',10,7)->comment('经度');
            $table->decimal('latitude',10,7)->comment('纬度');
            $table->softDeletes();
            $table->timestamps();
        });

        // 优秀教职工
        Schema::create('basic_excellent_teachers', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('优秀教师／学生代码');
            $table->string('avatar')->nullable()->comment('优秀教师／学生头像（职工表没有头像，上传保存）');
            $table->string('title')->comment('标题');
            $table->json('content')->comment('内容');
            $table->string('publisher')->comment('发布人');
            $table->softDeletes();
            $table->timestamps();
        });

        // 优秀学生
        Schema::create('basic_excellent_students', function (Blueprint $table) {
            // 表结构
            $table->bigIncrements('id')->comment('自增ID');
            $table->string('code')->comment('学生代码');
            $table->string('name')->comment('学生姓名');
            $table->string('grade')->comment('年级');
            $table->string('clazz')->comment('班级');
            $table->string('major')->comment('专业');
            $table->string('avatar')->nullable()->comment('学生头像');
            $table->string('title')->comment('标题');
            $table->json('content')->comment('内容');
            $table->string('publisher')->comment('发布人');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_users');
        Schema::dropIfExists('basic_terms');
        Schema::dropIfExists('basic_departments');
        Schema::dropIfExists('basic_faculties');
        Schema::dropIfExists('basic_colleges');
        Schema::dropIfExists('basic_excellent_teachers');
        Schema::dropIfExists('basic_excellent_students');
    }
}
